package com.migu.contacts.bean;

import android.text.TextUtils;

import com.migu.contacts.util.AvatarUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class ContactBean {
    public boolean checked;
    public String firstLetter;
    public int id;
    public String realName;
    public String namePinyin;
    public String nickName;
    public String englishName;
    public int gender;
    public String avatar;
    public String lunarBirthday;
    public String birthday;
    public int age;
    public String constellation;
    public String mobile;
    public String telephone;
    public String email;
    public int edu;
    public int maritalStatus;
    public int importance;
    public String note;
    public String common;
    public BirthdayTip birthdayContactsTip;
    public FestivalTip festivalContactsTip;
    public GiftTip giftTip;
    public int addType;
    public boolean birthdayTipStatus;
    public boolean festivalTipStatus;
    public boolean giftTipStatus;
    public boolean cycleTipStatus;
    public Object cycleTipContent;
    public List<Integer> contactsList;
    public String createTime;
    public List<JobList> jobList;
    public Address homeAddress;
    public Address currentAddress;
    public List<Integer> groupIdList;
    public List<Integer> labelIdList;
    public CycleTip contactsCycleTip;
    public List<ContactList> contactsRelationalList;
    public List<GroupBean> relationGroupList;

    public ContactBean() {
    }

    public String getRealName4Show() {
        if (TextUtils.isEmpty(realName)) {
            return "未命名";
        }
        return realName;
    }

    public String getNickName4Show() {
        if (TextUtils.isEmpty(nickName)) {
            return "昵称";
        }
        return nickName;
    }

    public String getEnglishName4Show() {
        if (TextUtils.isEmpty(nickName)) {
            return "英文名";
        }
        return englishName;
    }

    public String getIndustryName() {
        if (jobList != null && jobList.size() > 0) {
            JobList list = jobList.get(0);
            if (list != null) {
                String industryName = list.industryName;
                if (!TextUtils.isEmpty(industryName)) {
                    return industryName;
                }
            }
        }
        return "暂未填写";
    }

    public String getPositionName() {
        if (jobList != null && jobList.size() > 0) {
            JobList list = jobList.get(0);
            if (list != null) {
                String industryName = list.positionName;
                if (!TextUtils.isEmpty(industryName)) {
                    return industryName;
                }
            }
        }
        return "暂未填写";
    }

    public String getGender4Show() {
//        gender==1?"男":"女"
        if (gender == 1) {
            return "男";
        } else if (gender == 2) {
            return "女";
        }
        return "性别";
    }

    public ContactBean(DetailBean.ContactInfoList contactInfoList) {
        id = contactInfoList.contactId;
        realName = contactInfoList.realName;
        avatar = contactInfoList.avatar;
        gender = contactInfoList.gender == null ? 0 : gender;
        groupIdList = contactInfoList.groupList;
    }

    public String getBirthdayMothDay(int index) {
        String birthday1 = getBirthday(index);
        return birthday1.substring(birthday1.indexOf("-") + 1);
    }

    public static class CycleTip {
        public boolean tipStatus;
        public String tipTime;
        public int cycleType;
        public int cycleTime;
    }

    public static class Address {
        public String provinceCode;
        public String cityCode;
        public String countyCode;
    }

    public static class JobList {
        public int id;
        public String name;
        public int industryId;
        public String industryName;
        public int positionId;
        public String positionName;
        public String address;
    }

    @Override
    public boolean equals(Object object) {
        if (this == object) return true;
        if (object == null || getClass() != object.getClass()) return false;
        ContactBean that = (ContactBean) object;
        return id == that.id && Objects.equals(mobile, that.mobile);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, mobile);
    }

    public String getSex() {
        if (gender == 1) {
            return "男";
        }
        return "女";
    }

    public int getAvatarId() {
        return AvatarUtil.getAvatar(gender);
    }

    public static class ContactList {
        public int contactId;
        public List<Integer> groupIds;

        public ContactList(ContactBean bean) {
            contactId = bean.id;
            groupIds = new ArrayList<>();
            for (GroupBean groupBean : bean.relationGroupList) {
                groupIds.add(groupBean.id);
            }
        }
    }

    //1是阴历，0是阳历
    public String getBirthday(int addType) {
        if (addType == 0) {
            return birthday;
        }
        return lunarBirthday;
    }
}
